home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / beginner_gadgets / gadget3.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  4KB  |  136 lines

  1. /**************************************************************************
  2. *****                       Gadget Demo 3                             *****
  3. *****                                                                 *****
  4. *****                     by John J. Karcher                          *****
  5. *****                                                                 *****
  6. *****                       4 August 1992                             *****
  7. *****                       10 Jan 1993 mvk                           *****
  8. *****                                                                 *****
  9. **************************************************************************/
  10.  
  11. /*
  12.    This program opens up a window with a single gadget in it, using
  13.    egsgadbox.library.  This one is similar to the last one, but the
  14.    window is resizable and the gadget resizes with it!
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <exec/types.h>
  19. #include <proto/exec.h>
  20. #include <egs/egsintui.h>
  21. #include <egs/egsgadbox.h>
  22. #include <egs/proto/all.h>
  23.  
  24.  
  25. #define  ACTION_GAD_ID     1000
  26.  
  27.  
  28. struct Library *EGSIntuiBase;
  29. struct Library *EGBBase;
  30.  
  31. struct EB_GadContextNode   *GadCon;
  32. struct EI_Window           *Win;
  33.  
  34.  
  35. BYTE  CreateGfx(void);
  36. BYTE  CreateWindow(void);
  37.  
  38.  
  39. BYTE  CreateGfx(void)
  40. {
  41.    EB_GadBoxPtr           root, help;
  42.  
  43.    BYTE  ret = 0;
  44.  
  45.    if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
  46.      {
  47.       root = EB_CreateTextAction(GadCon, "Push Me", ACTION_GAD_ID, EB_FILL_ALL);
  48.       root = EB_CreateBackBorder(GadCon, root, 0);
  49.  
  50.       root = EB_CreateMasterWindow(GadCon,Win,root);
  51.  
  52.       if (EB_ProcessGadBoxes(GadCon, root))
  53.         {
  54.          ret = 1;
  55.         }
  56.      }
  57.  
  58.    return ret;
  59. }
  60.  
  61. BYTE  CreateWindow(void)
  62. {
  63.    BYTE  ret = 0;
  64.  
  65.    if (CreateGfx())
  66.      {
  67.             GadCon->NewWin->Title              = "EGS Gadget Demo 3";
  68.             GadCon->NewWin->IDCMPFlags        |= (EI_iCLOSEWINDOW | EI_iGADGETUP | EI_iNEWSIZE | EI_iSIZEVERIFY);
  69.             GadCon->NewWin->Flags             |= EI_WINDOWCENTER;
  70.             GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE  | EI_WINDOWSIZE);
  71.       if (Win = EI_OpenWindow(GadCon->NewWin))
  72.         {
  73.          ret = 1;
  74.         }
  75.      }
  76.  
  77.    return ret;
  78. }
  79.  
  80. main()
  81. {
  82.    struct EI_EIntuiMsg  *IMsg;
  83.    struct EI_Gadget     *TempGad;
  84.    BYTE  quit = 0;
  85.  
  86.    if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
  87.      {
  88.       if (EGBBase = OpenLibrary("egsgadbox.library", 0))
  89.         {
  90.          if (CreateWindow())
  91.            {
  92.             while (!quit)
  93.               {
  94.                WaitPort(Win->UserPort);
  95.                if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
  96.                  {
  97.                   if (IMsg->Class == EI_iCLOSEWINDOW)
  98.                     {
  99.                      quit = 1;
  100.                     }
  101.                   if (IMsg->Class == EI_iGADGETUP)
  102.                     {
  103.                      TempGad = (struct EI_Gadget *)IMsg->IAddress;
  104.                      if (TempGad->GadgetID == ACTION_GAD_ID)
  105.                        {
  106.                         printf("You pressed me!\n");
  107.                        }
  108.                     }
  109.                   if (IMsg->Class == EI_iSIZEVERIFY)
  110.                     {
  111.                      EI_RemoveGList(Win, GadCon->First, GadCon->Num);
  112.                      EB_DeleteGadContext(GadCon);
  113.                      GadCon = NULL;
  114.                     }
  115.                   if (IMsg->Class == EI_iNEWSIZE)
  116.                     {
  117.                      EI_LockIntuition();
  118.                      CreateGfx();
  119.                      if (GadCon)
  120.                        {
  121.                         EI_AddGList(Win, GadCon->First, GadCon->Num);
  122.                        }
  123.                      EI_UnlockIntuition();
  124.                     }
  125.                   ReplyMsg((struct Message *)IMsg);
  126.                  }
  127.               }
  128.            }
  129.          if (Win) EI_CloseWindow(Win);
  130.          if (GadCon) EB_DeleteGadContext(GadCon);
  131.          CloseLibrary(EGBBase);
  132.         }
  133.       CloseLibrary(EGSIntuiBase);
  134.      }
  135. }
  136.